import React, { useEffect } from 'react';
import { history, connect } from 'umi';
import { Form, Button, Input, notification } from 'antd';
import { getPageQuery } from '@/utils/utils';
import Particle from 'react-particles-js';
import style from './index.less';
import LoginComponents from './components/LoginComponents'
import './index.less'
const FormItem = Form.Item;
const filterRouter = (e = []) => {
  if (e.length > 0) {
    const { subAccessList = [], accessUrl = '', id } = e[0];
    if (accessUrl) {
      history.push({
        pathname: accessUrl,
        query: {
          accessId: id,
        },
      });
    } else {
      filterRouter(subAccessList);
    }
  }
  else {
    notification.warning({
      message: '温馨提示',
      description: '暂无权限，请联系管理员配置',
    });
  }

};
const LoginForm = ({ dispatch, loading }) => {
  const handleSearchsOver = (values) => {
    console.log(values)
    dispatch({
      type: 'login/fetchListLoginAdminAccess',
      callback: (e = []) => {
        filterRouter(e);
      },
    });
  };
  useEffect(() => {
    sessionStorage.clear();
  }, []);

  return (
    <div className='login_box_init'>
      <div className="login_container">
        <div className="left-panel">
          <div className="welcome-text">
            <h1 style={{ color: '#ffffff' }}>欢迎回来</h1>
            <p>登录您的账户，开始管理您的业务。我们为您提供安全、高效的管理体验。</p>
          </div>
        </div>
        <div className="right-panel">
          <div className="login-form">
            <h2>用户登录</h2>
            <LoginComponents handleSearchsOver={handleSearchsOver}></LoginComponents>
          </div>
        </div>
      </div>
    </div>


  );
};

export default connect(({ loading }) => ({ loading }))(LoginForm);
